#include<iostream>
#include<thread>
#include<future>
#include<string>

int myThread1(int val) {
    std::cout<<"线程1 ID = "<<std::this_thread::get_id()<<std::endl;
    std::chrono::milliseconds dura(5000);
    std::this_thread::sleep_for(dura);
    std::cout<<"线程1end"<<std::endl;
    return 6;
}

void myThread2(std::shared_future<int>& temp) {
    std::cout<<"线程2 ID = "<<std::this_thread::get_id()<<std::endl;
    auto res = temp.get();
    std::cout<<res<<std::endl;
    std::cout<<"线程2end"<<std::endl;
    return;
}

int main () {
    std::cout<<"main 线程 ID = "<<std::this_thread::get_id()<<std::endl;
    std::packaged_task<int(int)> mypt(myThread1);
    std::thread t1(std::ref(mypt), 66);
    t1.join();

    std::future<int> res = mypt.get_future();
    int x = res.get();
    std::shared_future<int> myres(res.share());
    int x1 = myres.get();
    int x2 = myres.get();
    
    std::thread t2(myThread2, std::ref(myres));
    t2.join();

    int x = 10;
    std::atomic<int>num;
    num = 10;

    

    return 1;
}